package com.eascs.web.o2o.web.reward.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.common.util.StringUtil;
import com.eascs.web.o2o.web.reward.dao.BaseDao;
import com.eascs.web.o2o.web.reward.entity.ProvinceSignForm;
import com.eascs.web.o2o.web.reward.service.SignForProvinceService;

@Service
public class SignForProvinceServiceImpl implements SignForProvinceService{
	
	@Autowired
	BaseDao baseDao;

	@Override
	public PageResult<Object[]> getProvinceSignList(ProvinceSignForm entity) {
		SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class, entity.getPageSize(), entity.getPageIndex());
		sqlPageQuery.setQuerySql(baseDao.getSql("sql.SignForProvinceServiceImpl.getProvinceSignList"));
		sqlPageQuery.addParam(entity.getDateStart());
		sqlPageQuery.addParam(entity.getDateEnd());
		sqlPageQuery.addParam(entity.getDateStart());
		sqlPageQuery.addParam(entity.getDateEnd());
		if(!StringUtil.isEmpty(entity.getProvinceName())) {
			sqlPageQuery.setQuerySql(sqlPageQuery.getQuerySql()+" and province_name=? ");
			sqlPageQuery.addParam(entity.getProvinceName());
		}
		sqlPageQuery.setQuerySql(sqlPageQuery.getQuerySql()+" order by t.sign_rate DESC ");
		return baseDao.findDataWithPage(sqlPageQuery);
	}

	@Override
	public PageResult<Object[]> getSignDetailList(ProvinceSignForm entity) {
		SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class, entity.getPageSize(), entity.getPageIndex());
		String querySql="select province_name,user_no,user_name,bill_code,loan_date,cancel_date,"
				+ "case when internal_sign=0 then '否' else '是' end is_ns,"
				+ "case when m_sign=0 then '否' else '是' end is_m "
				+ "from dm_evaluate_note_rate_all where /**DATA_PERMISSION(ltd)**/ "
				+ "((loan_date>=? and loan_date<=?) or (cancel_date>=? and cancel_date<=?)) ";
		sqlPageQuery.setQuerySql(querySql);
		sqlPageQuery.addParam(entity.getDateStart());
		sqlPageQuery.addParam(entity.getDateEnd());
		sqlPageQuery.addParam(entity.getDateStart());
		sqlPageQuery.addParam(entity.getDateEnd());
		if(!StringUtil.isEmpty(entity.getProvinceName())) {
			sqlPageQuery.setQuerySql(sqlPageQuery.getQuerySql()+" and province_name=? ");
			sqlPageQuery.addParam(entity.getProvinceName());
		}
		sqlPageQuery.setQuerySql(sqlPageQuery.getQuerySql()+" order by loan_date,cancel_date DESC ");
		return baseDao.findDataWithPage(sqlPageQuery);
	}

}
